package com.tarena.lbs.marketing.web.controller;

import com.tarena.lbs.base.protocol.exception.BusinessException;
import com.tarena.lbs.base.protocol.model.Result;
import com.tarena.lbs.base.protocol.pager.PageResult;
import com.tarena.lbs.marketing.web.service.CouponService;
import com.tarena.lbs.pojo.marketing.param.CouponParam;
import com.tarena.lbs.pojo.marketing.query.CouponQuery;
import com.tarena.lbs.pojo.marketing.vo.CouponVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;

//处理优惠券业务接口
@RestController
public class CouponController {
    @Autowired
    private CouponService couponService;
    @PostMapping("/admin/marketing/coupon/info/list")
    public Result<PageResult<CouponVO>> couponPage(@RequestBody CouponQuery query)
        throws BusinessException{
        PageResult<CouponVO> voPage=couponService.couponPage(query);
        return new Result<>(voPage);
    }
    //DAY12-PM 01优惠券表单新增提交
    @PostMapping("/admin/marketing/coupon/info/save")
    public Result<Void> couponSave(@RequestBody CouponParam param)
            throws BusinessException, ParseException {
        couponService.couponSave(param);
        return Result.success();
    }
    //小程序查询优惠券详情
    @GetMapping("/admin/marketing/coupon/info/detail/{id}")
    public Result<CouponVO> couponDetail(@PathVariable Integer id)
            throws BusinessException{
        CouponVO vo=couponService.couponDetail(id);
        return new Result<>(vo);
    }
}
